/*
 * FileName：VoteServiceImpl.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.wx.wxcms.service.impl;

import com.smart.common.util.AjaxResult;
import com.smart.common.util.StringUtil;
import com.smart.common.util.Util;
import com.smart.wx.wxcms.dao.VoteMapper;
import com.smart.wx.wxcms.entity.Vote;
import com.smart.wx.wxcms.service.VoteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 *
 *
 * @author hermit
 * @version 2.0
 * @date 2018-07-10 23:25:20
 */
@Service
public class VoteServiceImpl implements VoteService {

	@Resource
	private VoteMapper voteMapper;

	@Override
	public Vote queryObject(Vote vote1) throws Exception {

		Vote vote = this.voteMapper.queryObject(vote1);
		return vote;
	}

	@Override
	public List<Vote> queryList(Vote vote) throws Exception {

		List<Vote> list = this.voteMapper.queryList(vote);
		return list;
	}

	@Override
	public List<Vote> queryListByPage(Vote entity) throws Exception {

		List<Vote> list = this.voteMapper.queryListByPage(entity);
		return list;
	}

	@Override
	public Integer queryCount(Vote vote) throws Exception {

		return this.voteMapper.queryCount(vote);
	}

	@Override
	public Integer insert(Vote vote) throws Exception {
		return this.voteMapper.insert(vote);
	}

	@Override
	public Integer update(Vote vote) throws Exception {
		return this.voteMapper.update(vote);
	}

	@Override
	public Integer delete(Vote vote) throws Exception {
		String voteId = vote.getId();
		if(StringUtil.isNotBlank(voteId)){
			this.voteMapper.deleteBatch(Arrays.asList(voteId.split(",")));
		}
		return 1;
	}

	@Override
	public Integer deleteBatch(List<String> ids) throws Exception {
		return voteMapper.deleteBatch(ids);
	}

	@Override
	public AjaxResult saveOrUpdate(Vote vote) throws Exception {
		String voteId = vote.getId();
		if (StringUtil.isNotBlank(voteId)) { // 修改
			vote.setUpdatetime(new Date());
			this.voteMapper.update(vote);
		} else { // 新增
			vote.setId(Util.getUUID());
			vote.setCreatetime(new Date());
			vote.setUpdatetime(new Date());
			vote.setVoteState(0);
			this.voteMapper.insert(vote);
		}
		return AjaxResult.saveSuccess();
	}
}
